import { HttpError, toSuccess, useTransaction } from "@sker/core"
import { useData } from "@sker/runtime"
import { AutoTask } from "@sker/entities"
import { z } from "zod"

export default async () => {
    const input = z.object({
        id: z.string(),
        code: z.string()
    })
    const body = input.parse(useData())
    await useTransaction(async m => {
        const data = await m.findOne(AutoTask, { where: { id: parseInt(body.id) } })
        if (!data) {
            throw new HttpError(`未找到记录`)
        }
        await m.update(AutoTask, data.id, { code: body.code })
    })
    return toSuccess(true)
}
